/* part1test.c
 * test the syscall for the lock and condition
 */
#include "theater.h"
char * alL1="alL1";
char* rt1scl1="rt1scl1";
char *rt1scl2="rt1scl2";
char * rt1scc1="rt1scc1";
char *rt1scc2="rt1scc2";


void RT1AT1()
{
    CreateLock(alL1);
    Printf("rpctest 1:AT1 try to acquire a lock that named by RTAT \n");
    AcquireLock(alL1);
    Printf("rpctest 1:AT1 got the lock that named by RTAT \n");
}
void SMT1()
{
    char *mvname1 ="SMT1";
    int i;
    createMV(mvname1);
    if(i!=-1)
        Printf("rpctest 1:SMT1 create it succussfully, return %d \n",i);
    else
    {
        Printf("rpctest 1:SMT1 could not create it, return %d\n",i);
    }
    Printf("rpctest 1:set the mv %d to the value 55\n", i);
    setMV(mvname1,55);
}


void RT1SC1()
{
    CreateLock(rt1scl1);
    CreateCV(rt1scc1);
    AcquireLock(rt1scl1);
    Printf("rpctest 1:RT1SC1 is waiting for the lock %d  cv%d\n",rt1scl1,rt1scc1);
    WaitCV(rt1scl1,rt1scc1);
    Printf("rpctest 1:RT1SC1 wait up for the lock %d  cv%d\n",rt1scl1,rt1scc1);
    ReleaseLock(rt1scl1);
}

void SMT2()
{
    int i;
    int value;
    char * mvname1="SMT1";
    createMV(mvname1);
    if(i!=-1)
        Printf("rpctest 1:SMT1 create it succussfully, return %d \n",i);
    else
    {
        Printf("rpctest 1:SMT1 could not create it, return %d\n",i);
    }
    value=getMV(mvname1);
    Printf("rpctest 1:get the mv %d  the value %d \n ", i,value);
}

void RT1RT1()
{
    Printf("rpctest 1:RT1RT1 try to release a lock that named by RTAT \n");
    ReleaseLock(alL1);
}


void RT1BC1()
{
   CreateLock(rt1scl2);
    CreateCV(rt1scc2);
    AcquireLock(rt1scl2);
    Printf("rpctest 1:RT1BC1 is waiting for the lock %d  cv%d\n",rt1scl2,rt1scc2);
    WaitCV(rt1scl2,rt1scc2);
    Printf("rpctest 1:RT1BC1 waked up  for the lock %d  cv%d\n",rt1scl2,rt1scc2);
    ReleaseLock(rt1scl2);
}


int main()
{
    RT1LO1();
    RT1AT1();
    SMT1();
    RT1SC1();
    SMT2();
    RT1RT1();
    RT1BC1();
    Exit(0);
}

